﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataVisit.Model;
using NHibernate;
using System.Collections;
using NHibernate.Transform;

namespace DataVisit.DAL.ReportData
{
    public class DSettlementAnalysis:AbstractSupportDal<IProjectModel>
    {
        public IList GetData(string time)
        {
            //try
            //{
            var sql = Session.GetNamedQuery("GetData").QueryString.Replace("#yearname", YearReportName(time))
                .Replace("#hjname", HJReportName(time));
                IList list = Session.CreateSQLQuery(sql)
                    .SetTime("firsttime", Convert.ToDateTime(time))
                    .SetResultTransformer(Transformers.AliasToEntityMap).List();
                return list;
            //}
            //catch
            //{
            //    return null;
            //}
        }

        #region 组合成为数据表
        private string YearReportName(string s)
        { 
            return "R_2105_68_200_01_"+Convert.ToDateTime(s).ToString("yyyy-MM-dd").Split('-')[0]+"_"+Convert.ToDateTime(s).ToString("yyyy-MM-dd").Split('-')[1];
        }

        private string HJReportName(string s)
        {
            return "R_2105_68_003_300_" + Convert.ToDateTime(s).ToString("yyyy-MM-dd").Split('-')[0] + "_" + Convert.ToDateTime(s).ToString("yyyy-MM-dd").Split('-')[1];
        }
        #endregion
    }
}
